package com.ddpyjqtd.thread.threadcreate;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 
 * @Description: 通过线程池创建线程
 * 
 * @author: ddpyjqtd
 * @Date: 2019年5月13日
 *
 */
public class ByExecutorService extends Thread {

	public static void main(String[] args) {
		ExecutorService threadPool = Executors.newScheduledThreadPool(3);

		for (int i = 0; i < 5; i++) {
			final int taskI = i;
			threadPool.submit(new Runnable() {
				public void run() {
					for (int j = 0; j < 5; j++) {
						try {
							TimeUnit.SECONDS.sleep(1);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
						System.out.println("第个" + taskI + "线程的第" + j + "次循环执行。");
					}
				}
			});
		}
		threadPool.shutdown();// 任务执行完毕，关闭线程池  
	}
}
